# 练习1：密码评分等级
# 函数1--长度超过八位
def over_length(grade: int, passwd: str, problem: list):
    if len(passwd) > 8:
        grade += 1
    else:
        problem.append("密码长度未超过8位")
    return grade

# 函数2--三种以上符号（小写字母、大写字母、数字和其他字符）
def over_symbol(grade:int,passwd:str,problem:list):
    lower = 0
    upper = 0
    number = 0
    other = 0
    for i in passwd:
        if i >= 'a' and i <= 'z' :
            lower = 1
        elif i >= 'A' and i <= 'Z':
            upper = 1
        elif i >= '1' and i <= '9':
            number = 1
        else:
            other = 1
        if lower and upper and number + other ==4:
            break
    if lower + upper + number + other >= 3 :
        grade += 1
    else:
        problem.append("密码没有由三种以上的字符串组成")
    return grade

# 函数3--不能有长度超过或者等于3的子串重复
def no_repeat_substring(grade:int, passwd:str, problem:list):
    for i in range(len(passwd)-2):
        substr = passwd[i:i+3]
        if substr in passwd[i+3:]:
            problem.append("有长度超过或者等于三个的子串重复")
            return grade
    grade += 1
    return grade

grade = 2  # 等级分数
problem = []  # 扣分原因使用list存放
print("密码评分系统...")
passwd = input("请输入你的密码>>")

grade = over_length(grade, passwd, problem)

grade = over_symbol(grade, passwd, problem)

grade = no_repeat_substring(grade, passwd, problem)
# 根据grade评定等级,并输出需要改进的地方
if grade == 5:
    print("密码等级为5,没有要改进的地方")
else:
    print(f"密码等级为{grade},密码需要改进的地方:{problem}")
